package com.lagou.edu.controller;

import com.lagou.service.HelloService;
import com.lagou.util.TraceIpUtil;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/demoController")
public class DemoController {

    @Reference(filter = "TraceIpFilter")
    private HelloService helloService;

    /**
     * 示例demo
     *
     * @return
     */
    @RequestMapping("/demo")
    public String demo(HttpServletRequest request) throws InterruptedException {
        /**
         * 将客户端ip保存到ThreadLocal中
         */
        TraceIpUtil.setTraceIp(request.getRemoteHost());
        helloService.sayHello("dubbo");
        return "success";
    }

}
